package com.bl.student.api.controller.point;

import com.bl.student.api.controller.BaseController;
import com.bl.student.common.ApiResponseBody;
import com.bl.student.service.biz.point.PointService;
import com.bl.student.service.vo.point.PointListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by liangweikang on 19/6/22.
 */
@RestController
@Log4j2
@RequestMapping(value = {"/student/apis/point"})
@Api(value = "积分api", description = "积分api")
public class PointController  extends BaseController {


    @Autowired
    PointService pointService;

    @ApiOperation(value = "积分收入", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "IN 收入 OUT 支出 ALL 所有", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每List页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_list"})
    public ApiResponseBody<PointListVo> pointList(
            @RequestParam(value = "type", required = false, defaultValue = "1") String type,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        PointListVo pointListVo = pointService.getPointList(getUserInfo(request).getId(), type, pageable);

        return ApiResponseBody.createSuccessBody(pointListVo);
    }
}
